﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Operator
{
    /// <summary>
    /// OperatorLoginHistoryUserControl.xaml 的交互逻辑
    /// </summary>
    public partial class OperatorLoginHistoryUserControl : UserControl, IPlugin
    {
        private OperatorLoginHistoryService loginHistoryService = ServiceContainer.GetService<OperatorLoginHistoryService>();

        public OperatorLoginHistoryUserControl()
        {
            InitializeComponent();
        }

        public string Title
        {
            get { return "登录记录"; }
        }

        public Control UIControl
        {
            get { return this; }
        }

        private void btnQuery_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.pageBar.Parameters.Clear();
                string tbNumber = this.tbNumber.Text.Trim();
                DateTime? start = this.dpStart.SelectedDate;
                DateTime? end = this.dpEnd.SelectedDate;
                this.pageBar.Parameters.Add("number", tbNumber);
                this.pageBar.Parameters.Add("startTime", start);
                this.pageBar.Parameters.Add("endTime", end);
                this.pageBar.Parameters.Add("result", this.tbResult.SelectedIndex - 1);
                this.pageBar.StartPage();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void PageBarUserControl_PageChanging(object sender, PageBar.PageChangeEventArgs e)
        {
            var data = this.loginHistoryService.GetByAll(e.GetParameter<string>("number"), e.GetParameter<int>("result"), e.GetParameter<DateTime?>("startTime"), e.GetParameter<DateTime?>("endTime"), e.CurrentPage - 1, e.PageSize);
            this.dgvLoginHistories.ItemsSource = data.Datas;
            this.pageBar.Total = data.Total;
            this.pageBar.CurrentCount = data.Datas.Count;
        }
    }
}
